package template;

import java.util.ArrayList;
import java.util.List;

public class BigNumber {
    public static void main(String[] args) {
        //https://www.cnblogs.com/hello-dummy/p/11713558.html
        String a="1234567890345678934243253253545555777222";
        String b="88888888888888888222222222222227777777711";
//        System.out.println(bigNumberMultiply(a,b));
        System.out.println(bigNumberAdd("123","923"));

    }
    public static String bigNumberMultiply(String a,String b){
        String ans = "";
        int res[]=new int[a.length()+b.length()-1];
        for(int i=0;i<a.length();i++){
            for(int j=0;j<b.length();j++){
                int x=(a.charAt(i)-'0')*(b.charAt(j)-'0');//或者System.out.println(Character.valueOf('5')*Character.valueOf('6'));
                res[i+j]+=x;//此处注意是+=
            }
        }
        int flag=0;
        int m;
        for(int i=res.length-1;i>=0;i--){
            m=res[i]+flag;
            ans=m%10+ans;
            flag=m/10;
        }
        if(flag!=0){
            ans=flag+ans;
        }
        return ans;
    }
    public static String bigNumberAdd(String a,String b){
        if(a.length()==0&&b.length()==0) return "";
        if(a==null||a=="") return  b;
        if(b==null||b=="") return a;

        String ans = "";

        int len=(a.length()-b.length())>0?a.length():b.length();
        int res[]=new int[len];
        for(int i=0;i<len;i++){
            if(i<a.length()&&i<b.length()){
                res[i]=(a.charAt(i)-'0')+(b.charAt(i)-'0');
            }else if(i<a.length()&&i>=b.length()){
                res[i]=(a.charAt(i)-'0');
            }else if(i>=a.length()&&i<b.length()){
                res[i]=(b.charAt(i)-'0');
            }
        }
        int flag=0;
        int m;
        for(int i=res.length-1;i>=0;i--){
            m=res[i]+flag;
            ans=m%10+ans;
            flag=m/10;
        }
        if(flag!=0){
            ans=flag+ans;
        }
        return ans;
    }
}
